<include file="Public/min-header"/>
<div class="wrapper">
    <include file="Public/breadcrumb"/>
    <section class="content">
        <div class="row">
            <div class="col-sm-12">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title">增加奖品</h3>
                        <div class="pull-right">
                            <a href="{:U('Lottery/prizeList')}" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="返回"><i class="fa fa-reply"></i></a>
                        </div>
                    </div>

                    <!-- /.box-header -->
                    <form action="{:U('Lottery/addPrize')}" method="post" enctype="multipart/form-data" class="form-horizontal">
                        <div class="box-body">
                            <input type="hidden" name="prize_id" value="{$lotteryData.prize_id}">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">奖品名称</label>
                                <div class="col-sm-6">
                                    <input type="text" placeholder="名称" class="form-control large" name="prize_name" value="{$lotteryData.prize_name}">
                                    <span class="help-inline" style="color:#F00; display:none;" id="err_name"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-2">分类分组:</label>

                                <div class="col-sm-3">
                                    <select name="category_id" id="cat_group" class="form-control">
                                        <!-- <option value="0">默认未中奖</option> -->
                                        <foreach name="lotteryCategoryData" item="v" key="k" >
                                            <option value="{$v['id']}"<if condition="$lotteryData[category_id] eq $v['id']">selected="selected"</if>>
                                                {$v['category_name']}
                                            </option>
                                        </foreach>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group" style="display:none;">
                                <label class="control-label col-sm-2">是否校验库存:</label>

                                <div class="col-sm-3">
                                    是 <input type="radio"<if condition="$lotteryData[check_num] eq 1">checked="checked"</if> value="1" name="check_num" />
                                    否 <input type="radio"<if condition="$lotteryData[check_num] eq 0">checked="checked"</if> value="0" name="check_num" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-2">权重(总权重为100，未中奖权重为100扣除所有奖品权重)</label>
                                <div class="col-sm-6">
                                    <input type="text" placeholder="权重(当前可输入最大值{$prize_weight})" class="form-control large" name="prize_weight" value="{$lotteryData.prize_weight}">
                                    <span class="help-inline" style="color:#F00; display:none;" id="err_mobile_name"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label col-sm-2">数量</label>
                                <div class="col-sm-6">
                                    <input type="text" placeholder="数量" class="form-control large" name="prize_num" value="{$lotteryData.prize_num}">
                                    <span class="help-inline" style="color:#F00; display:none;"></span>
                                </div>
                            </div>
                            <?php
                            if( $lotteryData['category_id'] == $coupon_prize_type || $lotteryData['category_id'] == $money_prize_type ){
                            ?>
                            <div class="form-group coupon_set">
                                    <label class="control-label col-sm-2">
                                        面额(如果设置将会自动为用户发放)</label>
                                    <div class="col-sm-6">
                                        <input type="number" placeholder="请输入面额" class="form-control large" name="coupon_id" id="coupon_id" value="{$lotteryData.coupon_id}">  
                                        <span class="help-inline" style="color:#F00; display:none;"></span>
                                    </div>
                                </div>
                            </div>

                            <?php 
                            }
                            ?>
                               
                            <div class="form-group">
                                <label class="control-label col-sm-2">奖品展示图片</label>

                                <div class="col-sm-10">
                                    <input type="file" name="prize_img" value="上传图片"/>
                                    <!--<input type="text" value="{$lotteryData.prize_img}" name="image" id="image" class="form-control large" readonly="readonly"  style="width:500px;display:initial;"/>-->
                                </div>
                            </div>
                            <div class="form-group" style="display: none;">
                                <label class="control-label col-sm-2">显示排序</label>
                                <div class="col-sm-1">
                                    <input type="text" placeholder="50" class="form-control large" name="prize_sort" value="{$lotteryData.prize_sort}"/>
                                    <span class="help-inline" style="color:#F00; display:none;" id="err_sort_order"></span>
                                </div>
                            </div>
                        </div>
                        <div class="box-footer">
                            <!--<input type="hidden" name="id" value="{$goods_category_info.id}">-->
                            <button type="reset" class="btn btn-primary pull-left"><i class="icon-ok"></i>重填  </button>
                            <button type="submit" class="btn btn-primary pull-right"><i class="icon-ok"></i>提交  </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>
</div>

<script>

$(document).on("change","select[name='category_id']",function(){
    console.log(this.value);
    if( this.value == '{$coupon_prize_type}' || this.value == '{$money_prize_type}' )
    {
        $(".coupon_set").show();
    }else{
        $(".coupon_set").hide();
        $("#coupon_id").val(0);
    }
})
$(document).on("click","#coupon_name",function(){
    showCouponSelector();
})

var iframe = null;

window.getPrizeCoupon = function(opt)
{
    console.log(opt);
    $("#coupon_name").html(opt.name);
    $("#coupon_id").val(opt.id);
    layer.close(iframe);
}

var showCouponSelector = function()
{
    iframe = layer.open({
      type: 2,
      title: "选择代金券",
      closeBtn: 1, //不显示关闭按钮
      shade: [0],
      area: ['800px', '500px'], //宽高
      time: 0, //2秒后自动关闭
      anim: 2,
      content: ["{:U('Coupon/coupon_list_for_prize')}"], //iframe的url，no代表不显示滚动条
      end: function(){ //此处用于演示
         
      }
    });
    console.log(iframe)
}

</script>

</body>
</html>